package com.example.springbootlearn.listener;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;

/**
 * @author caiji Mr. Li
 * @date 2019/10/28 18:13
 */
public class Main {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.registerBean(MyEventListener.class);
        context.refresh();
        context.close();
//        context.publishEvent(new BlackListEvent("wawa", "guangzhou", "hello"));
    }

    public static abstract class AbstractEventListener {

        @EventListener(ContextRefreshedEvent.class)
        public void onContextRefreshEvent(ContextRefreshedEvent event) {
            System.out.println("abstractEventListener : " + event.getClass().getSimpleName());
        }
    }

    public static class MyEventListener extends AbstractEventListener {
        @EventListener(ContextClosedEvent.class)
        public boolean onContextClosedEvent(ContextClosedEvent event) {
            System.out.println("MyEventListener : " + event.getClass().getSimpleName());
            return true;
        }
    }
}
